import Mock from "mockjs";

// 定义数据类型
let { data } = Mock.mock({
  // 150条数据
  "data|150": [
    {
      // 排名
      "goodsId|+1": 1,
      // 用户名
      usename: "@ctitle(3)",
      //地区
      Address: "@county(true)",
      // 数量
      "counts|100-20000": 120,
      // 成交
      "downMoney|30-500": 30,
      // //随机时间
      date: "@datetime()",
    },
  ],
});

class ProductServer {
  getData({ page, size }) {
    return new Promise((resolve) => {
      // 分页截取
      const result = data.slice((page - 1) * size, page * size);
      resolve({
        status: 0,
        // result:["1","2","3"],
        result: result,
        count: data.length,
      });
    });
  }
  removeData({ goodsId }) {
    return new Promise((resolve) => {
      data = data.filter((item) => item.goodsId !== goodsId);
      resolve({
        status: 0,
        msg: "删除成功",
      });
    });
  }
}

const product = new ProductServer();
export default product;
